package com.ash.jna;

import java.io.UnsupportedEncodingException;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.win32.StdCallLibrary;

/** Simple example of JNA interface mapping and usage. */
public class HelloWorld {

    // This is the standard, stable way of mapping, which supports extensive
    // customization and mapping of Java to native types.

    public interface CLibrary extends Library {
        CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);

        void printf(String format, Object... args);
    }

    public interface HISSICP3 extends StdCallLibrary {

        int initservice(String s, int appCode, byte[] data);

    }

    public interface Xianshiqi extends StdCallLibrary {
        void javaTestPrintf();
    }

    public static void main(String[] args) {
        String path = (HelloWorld.class.getResource("/").getPath()).replaceAll("%20", " ").substring(1).replace("/", "\\");
        String DLL_PATH = null;
        try {
            DLL_PATH = java.net.URLDecoder.decode(path, "utf-8");
            System.out.println(DLL_PATH);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        // String myLibraryPath = System.getProperty("user.dir");
        // System.out.println(myLibraryPath);
        System.out.println(System.getProperty("java.library.path"));
        // System.setProperty("java.library.path", myLibraryPath);

        Xianshiqi xianshiqi = (Xianshiqi) Native.loadLibrary(DLL_PATH + "test\\xianshiqi.dll", Xianshiqi.class);
        xianshiqi.javaTestPrintf();

        // byte[] d = new byte[1024];
        // Integer i = 0;
        // HISSICP3 INSTANCE = (HISSICP3) Native.loadLibrary(DLL_PATH + "dll\\HISSICP3", HISSICP3.class);
        //
        // INSTANCE.initservice("d", i, d);
    }
}